home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / Offscreen.cp < prev    next >
Text File  |  1993-08-26  |  4KB  |  136 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| This file contains the routines which manipulate the off-screen pixmap
  3. //|________________________________________________________________________________
  4.  
  5. #include "HyperCuber Errors.h"
  6.  
  7. #include <Exceptions.h>
  8. #include <TCLUtilities.h>
  9.  
  10.  
  11.  
  12. //============================ Globals ============================\\
  13.  
  14. CGrafPort            left_offscreen_cport;        //  The offscreen grafport for left eye view,
  15.                                                 //    or for the only view if viewing in mono
  16. CGrafPtr            left_offscreen_cptr = &left_offscreen_cport;
  17. CGrafPtr            offscreen_cptr = &left_offscreen_cport;
  18.  
  19. CGrafPort            right_offscreen_cport;        //  The offscreen grafport for right eye view
  20. CGrafPtr            right_offscreen_cptr = &right_offscreen_cport;
  21.  
  22. extern Boolean        drawing_disabled;
  23.  
  24.  
  25. //============================ Prototypes ============================\\
  26.  
  27. void create_offscreen_pixmap(CGrafPort *color_port, Rect *bounds);
  28. void dispose_offscreen_pixmap(CGrafPort *color_port);
  29. void adjust_offscreen_pixmap(CGrafPort *color_port, Rect *bounds);
  30.  
  31. extern void general_error(short error);
  32.  
  33.  
  34.  
  35. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  36. //| Procedure: create_offscreen_pixmap
  37. //|
  38. //| Purpose: create a new offscreen pixmap
  39. //|
  40. //| Parameters: color_port: points to CGrafPort to act as port
  41. //|             bounds:     boundaries to use for pixmap
  42. //|______________________________________________________________
  43.  
  44. void create_offscreen_pixmap(CGrafPort *color_port, Rect *bounds)
  45. {
  46.  
  47.     GrafPtr temp_port;    
  48.     GetPort (&temp_port);                                        //  Save the current GrafPort
  49.  
  50.     OpenCPort(color_port);                                        //  Create a new CGrafPort
  51.  
  52.     SetPort((GrafPtr) color_port);                                //  Make this the current port
  53.     TextFont(applFont);                                            //  Change the font to application
  54.  
  55.     short width = ((bounds->right - bounds->left + 3) / 4) * 4;    //  Round width to longword
  56.     short height = bounds->bottom - bounds->top;
  57.  
  58.     Ptr base_address = NewPtr(width * height);                    //  Allocate space for bitmap
  59.  
  60.     if (!base_address)
  61.         ExitToShell();                                            //  Should never happen, since
  62.                                                                 //    bitmap starts at 1x1
  63.  
  64.     PixMap *pixmap = *(*color_port).portPixMap;                    //  Get pointer to the PixMap
  65.     pixmap->baseAddr = base_address;
  66.     pixmap->rowBytes = width;
  67.     pixmap->rowBytes |= 32768;                                    //  Make it a PixMap
  68.     pixmap->bounds = *bounds;
  69.     pixmap->pixelSize = 8;
  70.     pixmap->cmpCount = 1;
  71.     pixmap->cmpSize = 8;
  72.  
  73.     SetPort(temp_port);                                            //  Restore the old port
  74.  
  75. }    //==== create_offscreen_pixmap() ====\\
  76.  
  77.  
  78.  
  79. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  80. //| Procedure: adjust_offscreen_pixmap
  81. //|
  82. //| Purpose: adjust an existing offscreen pixmap so it is as large as bounds
  83. //|
  84. //| Parameters: color_port: the CGrafPort containing the pixmap
  85. //|             bounds:     new boundaries to use for pixmap
  86. //|___________________________________________________________________________________
  87.  
  88. void adjust_offscreen_pixmap(CGrafPort *color_port, Rect *bounds)
  89. {
  90.  
  91.     short new_width = bounds->right - bounds->left;        //  Find new size
  92.     short new_row_bytes = ((new_width + 3) / 4) * 4;
  93.     short new_height = bounds->bottom - bounds->top;
  94.         
  95.     DisposPtr((**(*color_port).portPixMap).baseAddr);        //  Dispose of old bitmap
  96.     
  97.     
  98.     Handle base_handle =
  99.             NewHandleCanFail(new_row_bytes * new_height);    //  Check if there's enough memory
  100.     if (base_handle == NULL)
  101.         {
  102.         general_error(bitmap_too_large);                    //  Tell user about error
  103.         drawing_disabled = TRUE;                            //  Disable drawing
  104.         return;
  105.         }
  106.         
  107.     DisposHandle(base_handle);
  108.     Ptr base_address = NewPtr(new_row_bytes * new_height);    //  Allocate space for bitmap
  109.  
  110.     Rect new_bounds = {0, 0, new_height, new_width};
  111.  
  112.     (**(*color_port).portPixMap).baseAddr = base_address;        //  Set up new pixmap bounds
  113.     (**(*color_port).portPixMap).rowBytes = new_row_bytes + 0x8000;
  114.     (**(*color_port).portPixMap).bounds = new_bounds;
  115.     
  116. }    //==== adjust_offscreen_pixmap() ====\\
  117.  
  118.  
  119. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. //| Procedure: dispose_offscreen_pixmap
  121. //|
  122. //| Purpose: dispose of an offscreen pixmap
  123. //|
  124. //| Parameters: color_port: the offscreen CGrafPort
  125. //|______________________________________________________________
  126.  
  127. void dispose_offscreen_pixmap(CGrafPort *color_port)
  128. {
  129.  
  130.     DisposPtr((**(*color_port).portPixMap).baseAddr);
  131.     CloseCPort(color_port);
  132.  
  133. }    //==== dispose_offscreen_pixmap() ====\\
  134.  
  135.  
  136.